<template>
	<view class="container">
		<view class="header_area flex">
			<view class="head_nav" v-for="(item, index) in tab_list" :key="index"  :class="{current: filterIndex === index}" @click="tabClick(index)">
				{{ item.title }}
			</view>
		</view>
		<view class="subsidiary_wrap" v-if="filterIndex===0">
			<view class="subsidiary_box flex" v-for="(item, index) in earn" :key="index">
				<view class="subsidiary_left">
					<view class="subsidiary_title">{{ sonType_arr[item.sonType - 1] }}</view>
					<view class="subleft_bot flex">
						<view class="subleft_time">{{ item.integralTime | dateFormat }}</view>
					</view>
				</view>
				<view class="subsidiary_right">+{{ item.changeIntegral }}</view>
			</view>
		</view>
		
		<view class="subsidiary_wrap" v-if="filterIndex===1">
			<view class="subsidiary_box flex" v-for="(item, index) in consume" :key="index">
				<view class="subsidiary_left">
					<view class="subsidiary_title">{{ sonType_arr[item.sonType - 1] }}</view>
					<view class="subleft_bot flex">
						<view class="subleft_time">{{ item.integralTime | dateFormat }}</view>
					</view>
				</view>
				<view class="subsidiary_right">-{{ item.changeIntegral }}</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			filterIndex: 0,
			tab_list: [{title: '获取积分'}, {title: '消耗积分'}],
			earn: [],
			consume: [],
			sonType_arr: ['分享','邀请好友','签到','充值','消费','兑换商品','兑换优惠券']
		};
	},
	onHide() {
	},
	destroyed() {
	},
	onShow() {
	},
	onLoad() {
		this.initData(1)
		this.initData(2)
	},
	onShareAppMessage() {
		const that = this
		return {
			title: '光合优选-在线商城',
			imageUrl: 'http://shopmalling-asset.oss-cn-hangzhou.aliyuncs.com/share_bg.jpg',
			path: '/pages/index/index'
		}
	},
	methods: {
		initData(type) {
			this.$api.request('integralDetail', 'detailList', {
				type:type
			}, failres => {
				this.$api.msg(failres.errmsg)
			}).then(res => {
				if(type == 1){
					this.earn = res.data.reverse()
				}
				if(type == 2){
					this.consume = res.data.reverse()
				}
			})
		},
		sonType() {
			
		},
		//筛选点击
		tabClick(index) {
			if (this.filterIndex === index && index !== 1) {
				return;
			}
			this.filterIndex = index;
			
			// uni.pageScrollTo({
			// 	duration: 300,
			// 	scrollTop: 0
			// })
			// this.loadData('refresh', 1);
			// uni.showLoading({
			// 	title: '正在加载'
			// })
		}
	}
};
</script>

<style lang="scss" scoped>
.container {
	display: flex;
	width: 100%;
	min-height: 100vh;
	background: #FFFFFF;
	flex-direction: column;
	align-items: center;
}
.flex {
	display: flex;
}

::-webkit-scrollbar {
	width: 0;
	height: 0;
	color: transparent;
}

.header_area{
	position: fixed;
	left: 0;
	top: var(--window-top);
	display: flex;
	width: 100%;
	height: 80upx;
	background: #fff;
	box-shadow: 0 2upx 10upx rgba(0, 0, 0, .06);
	z-index: 10;
	
	// width: 60%;
	// border-radius: 40upx;
	// background-color: rgb(238,238,238);
	// justify-content: center;
	// left: 50%;
	// transform: translate3d(-50%, 0, 0);

	.head_nav {
		flex: 1;
		display: flex;
		justify-content: center;
		align-items: center;
		height: 100%;
		font-size: 30upx;
		color: $font-color-dark;
		position: relative;
		&.current {
			color: $base-color;
			
			&:after {
				content: '';
				position: absolute;
				left: 50%;
				bottom: 0;
				transform: translateX(-50%);
				width: 120upx;
				height: 0;
				border-bottom: 4upx solid $base-color;
			}
		}
	}
	// .navleft{
	// 	border-radius: 40upx 0 0 40upx;
	// 	background-color: #FF4B67;
	// 	color: #fff;
	// }
	// .navright{
	// 	border-radius: 0upx 40upx 40upx 0;
	// 	background-color: #FF4B67;
	// 	color: #fff;
	// }
}

.subsidiary_wrap{
	margin-top: 100upx;
	width: 100%;
}
.subsidiary_box{
	width: 100%;
	height: 122upx;
	justify-content: space-between;
	align-items: center;
	padding: 10upx 42upx;
	border-bottom: solid 1upx #C9C9C9;
	.subsidiary_left{
		.subsidiary_title{
			font-size: 28upx;
			font-weight: 600;
			line-height: 60upx;
		}
		.subleft_bot{
			justify-content: space-around;
			.subleft_time{
				color: #7E7E7E;
				font-size: 24upx;
			}
		}
	}
	.subsidiary_right{
		color: #ACACAC;
		font-size: 26upx;
	}
}
</style>
